/*
 * 提交板块编辑Ajax:
 * 与后端的交互: 除内部错误500外其他情况为200
 * 200后解析数据
 * 后端返回String: code#content,  code is int, content is string
 * 注册成功返回"0#成功信息", 注册失败返回"1#失败原因"
 */
function BlockEdit()
{
	var blockId = $("#blockId").text();                          			//raw string

	var blockParentidGroup = $("input[name='blockParentid']:checked").attr("id");  	//raw string
	var blockParentid = blockParentidGroup.split('#')[1];
	
	var blockTitle = $("#blockTitle").val();                          		//raw string
	//注意:editor应当在外部定义, 当前在html中
	var blockDescribe = $('.editormd-markdown-textarea').val();
	var blockState = $("input[name='blockState']:checked").val();           //raw string

	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	 }
	else
	{	// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
		    if (xmlhttp.status==200)
			{
				var response = xmlhttp.responseText.split("#");
				var code = parseInt(response[0])
				var str = response[1]
				if (code == 0)
				{
				    $("#backendInfo").val("成功:" + str + ",3秒后跳转到板块列表页");
				    window.setTimeout("window.location='/cms/blocklist.html'", 3000);
				}
			    else
				{
					$("#backendInfo").val(str);
				}
			}
			else
			{
			    $("#backendInfo").val("内部错误");
			}
		}
	}
	xmlhttp.open("POST","blockeditPOST",true);
	xmlhttp.setRequestHeader("Content-type","application/json;charset=UTF-8");
	xmlhttp.send(JSON.stringify(
				{ "blockParentid": blockParentid,
				  "blockId": blockId,
				  "blockTitle": blockTitle,  "blockDescribe": blockDescribe,
				  "blockState": blockState
				}
			));
}
